#ifndef LONGKEY_COMMON_EXTRA_ARGS_PARSER_H_
#define LONGKEY_COMMON_EXTRA_ARGS_PARSER_H_

#include <Windows.h>
#include <atlstr.h>
#include "../base/basictypes.h"
#include "command_line.h"

// This class handles tokenizing and parsing the ExtraArgs portion of the
// command line.
// The format of the extra arguments is as follows:
// appguid={}&.....appguid={}....
// appguid has to be the first value of the extra arguments.
// Each appguid defines one product.

class ExtraArgsParser
{
public:
	ExtraArgsParser() : first_app_(false) { }

	// Parses the extra_args (the tag) and app_args (/appargs) strings, storing
	// the results in args.
	HRESULT Parse(const TCHAR* extra_args,
		const TCHAR* app_args,
		CommandLineExtraArgs* args);

private:
	HRESULT ParseExtraArgs(const TCHAR* extra_args, CommandLineExtraArgs* args);

	// Performs validation against extra_args and if it's valid, stores the
	// extra_args value into args->extra_args.
	HRESULT HandleToken(const CString& token, CommandLineExtraArgs* args);

	CommandLineArgs cur_extra_app_args_;
	bool first_app_;

	DISALLOW_EVIL_CONSTRUCTORS(ExtraArgsParser);
};

#endif	// LONGKEY_COMMON_EXTRA_ARGS_PARSER_H_